package edu.gdpu.classloader;

/**
 * @author mazebin
 * @date 2021年 07月08日 16:48:15
 */
public class ClassLoaderTest25 implements Runnable {
    private Thread thread;

    public ClassLoaderTest25() {
        this.thread = new Thread(this);
        thread.start();
    }

    @Override
    public void run() {
        ClassLoader loader = thread.getContextClassLoader();
        thread.setContextClassLoader(loader);
        System.out.println("class:"+loader.getClass());
        System.out.println("parent:"+loader.getParent());
        /**
         * 输出结果
         * class:class sun.misc.Launcher$AppClassLoader
         * parent:sun.misc.Launcher$ExtClassLoader@2cf062b0
         */
    }

    public static void main(String[] args) {
        ClassLoaderTest25 classLoaderTest25 = new ClassLoaderTest25();
    }
}
/**
 * 底层Launcher源码
 * public Launcher() {
 *
 *         Launcher.ExtClassLoader var1;
 *         try {
 *         //获取扩展类加载器
 *             var1 = Launcher.ExtClassLoader.getExtClassLoader();
 *         } catch (IOException var10) {
 *             throw new InternalError("Could not create extension class loader", var10);
 *         }
 *
 *         try {
 *         //获取应用类加载器
 *             this.loader = Launcher.AppClassLoader.getAppClassLoader(var1);
 *         } catch (IOException var9) {
 *             throw new InternalError("Could not create application class loader", var9);
 *         }
 *        //将应用类加载器设置线程上下文类加载器
 *         Thread.currentThread().setContextClassLoader(this.loader);
 *         String var2 = System.getProperty("java.security.manager");
 *         if (var2 != null) {
 *             SecurityManager var3 = null;
 *             if (!"".equals(var2) && !"default".equals(var2)) {
 *                 try {
 *                     var3 = (SecurityManager)this.loader.loadClass(var2).newInstance();
 *                 } catch (IllegalAccessException var5) {
 *                 } catch (InstantiationException var6) {
 *                 } catch (ClassNotFoundException var7) {
 *                 } catch (ClassCastException var8) {
 *                 }
 *             } else {
 *                 var3 = new SecurityManager();
 *             }
 *
 *             if (var3 == null) {
 *                 throw new InternalError("Could not create SecurityManager: " + var2);
 *             }
 *
 *             System.setSecurityManager(var3);
 *         }
 *
 *     }
 */
